<template>
  <div class="rated">
    <p class="title">最受好评电影</p>

    <div class="top-rated-list">
      <div class="rated-wrap">
        <div
          class="rated-item"
          v-for="item in ratedList"
          :key="item.id"
          @click="goToDetail(item.id)"
        >
          <div class="img">
            <img :src="item.img" alt="" />
            <div class="shadow" v-if="item.sc">观众评分：{{ item.sc }}</div>
            <div class="shadow" v-else>{{ item.wish }}人想看</div>
          </div>

          <span>{{ item.nm }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ratedList: [],
    };
  },
  mounted() {
    fetch("http://118.24.239.63:3000/api/rated/list")
      .then((response) => response.json())
      .then((res) => {
        if (res.success) {
          this.ratedList = res.data;
        }
      });
  },
  methods: {
    goToDetail(id) {
      // console.log(id);

      this.$router.push("/detail/" + id);
    },
  },
};
</script>

<style lang="less" scoped>
.rated {
  width: 375px;
  height: 205px;
  border-bottom: 1px solid @border-color;
  padding: 12px 15px;
  background-color: #fff;

  .title {
    font-size: 14px;
    color: #333;
    margin: 0 0 12px;
  }

  .top-rated-list {
    width: 100%;
    height: 148px;
    overflow: auto;

    &::-webkit-scrollbar {
      display: none;
    }

    .rated-wrap {
      width: 100%;
      height: 100%;
      display: flex;

      .rated-item {
        width: 85px;
        height: 100%;
        margin-right: 10px;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;

        &:last-child {
          margin: 0;
        }

        .img {
          width: 85px;
          height: 115px;
          position: relative;

          img {
            width: 85px;
            height: 115px;
          }

          .shadow {
            position: absolute;
            width: 100%;
            height: 30px;
            left: 0;
            bottom: 0;
            background-image: linear-gradient(
              to bottom,
              rgba(0, 0, 0, 0),
              rgba(0, 0, 0, 1)
            );
            color: rgb(250, 175, 0);
            font-size: 11px;
            font-weight: 900;
            display: flex;
            align-items: flex-end;
            padding: 3px;
          }
        }

        span {
          margin-top: 5px;
          font-size: 13px;
          font-weight: 900;
          .ell();
        }
      }
    }
  }
}
</style>
